/*
 * This file is part of aion-engine <aion-engine.com>
 *
 * aion-engine is private software: you can redistribute it and or modify
 * it under the terms of the GNU Lesser Public License as published by
 * the Private Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * aion-engine is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser Public License for more details.
 *
 * You should have received a copy of the GNU Lesser Public License
 * along with aion-engine.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.aionengine.gameserver.model.geometry;

import com.aionengine.gameserver.utils.MathUtil;
import com.aionengine.gameserver.world.zone.ZoneName;


/**
 * @author Rolandas
 */
public class SemisphereArea extends SphereArea {

    public SemisphereArea(ZoneName zoneName, int worldId, float x, float y, float z, float r) {
        super(zoneName, worldId, x, y, z, r);
    }

    @Override
    public boolean isInside3D(Point3D point) {
        return this.z < point.getZ() && MathUtil.isIn3dRange(x, y, z, point.getX(), point.getY(), point.getZ(), r);
    }

    @Override
    public boolean isInside3D(float x, float y, float z) {
        return this.z < z && MathUtil.isIn3dRange(x, y, z, this.x, this.y, this.z, r);
    }

    @Override
    public boolean isInsideZ(Point3D point) {
        return isInsideZ(point.getZ());
    }

    @Override
    public float getMinZ() {
        return z;
    }

    @Override
    public float getMaxZ() {
        return z + r;
    }

    @Override
    public double getDistance3D(Point3D point) {
        return getDistance3D(point.getX(), point.getY(), point.getZ());
    }

    @Override
    public double getDistance3D(float x, float y, float z) {
        double distance = MathUtil.getDistance(x, y, z, this.x, this.y, this.z) - r;
        if (z < this.z)
            return distance;
        return distance > 0 ? distance : 0;
    }

    @Override
    public boolean intersectsRectangle(RectangleArea area) {
        if ((area.getMaxZ() >= z || z <= area.getMinZ()) && area.getDistance3D(x, y, z) <= r)
            return true;
        return false;
    }


}
